package com.ruoyi.tzzl.service.imp;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.tzzl.domain.WzMessageLogging;
import com.ruoyi.tzzl.mapper.WzFocusonMapper;
import com.ruoyi.tzzl.mapper.WzMessageLoggingMapper;
import com.ruoyi.tzzl.service.IWzMessageLoggingService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author by caoyong
 * @date 2022/12/10
 **/
@Service
public class WzMessageLoggingServiceImpl extends ServiceImpl<WzMessageLoggingMapper, WzMessageLogging> implements IWzMessageLoggingService {

    /**
     * 刷新消息记录
     *
     * @param wzMessageLogging
     */
    @Override
    public boolean addMessageRecord(WzMessageLogging wzMessageLogging) {
        LambdaUpdateWrapper<WzMessageLogging> lqw =new LambdaUpdateWrapper<>();
        lqw.set(WzMessageLogging::getWhetherRead,"1");
        lqw.eq(WzMessageLogging::getReceiveId,wzMessageLogging.getReceiveId());
        return this.update(lqw);
    }

    /**
     * 查询用户消息记录
     *
     * @param id
     */
    @Override
    public List<WzMessageLogging> getMessageRecord(Long id) {
        LambdaQueryWrapper<WzMessageLogging> lqw =new LambdaQueryWrapper<>();
        lqw.eq(WzMessageLogging::getReceiveId,id);
        lqw.orderByDesc(WzMessageLogging::getCreateTime);
        return this.list(lqw);
    }

    /**
     * 查看新消息记录数
     *
     * @param id
     */
    @Override
    public int newMessage(Long id) {
        LambdaQueryWrapper<WzMessageLogging> lqw =new LambdaQueryWrapper<>();
        lqw.eq(WzMessageLogging::getReceiveId,id);
        lqw.eq(WzMessageLogging::getWhetherRead,"0");
        return this.list(lqw).size();
    }
}

